#!/usr/bin/python
#-*- coding: utf-8 -*-

import re

mesh_file = open("d2013.bin", 'r')
mesh_hash = {}

for line in mesh_file.readlines():
    name_match = re.search(r'^MH = (.+)$', line.strip())
    if name_match:
        name = name_match.group(1)
    
    number_match = re.search(r'^MN = (.+)$', line.strip())
    if number_match:
        number = number_match.group(1)
        mesh_hash[number] = name

mesh_file.close()

keylist = mesh_hash.keys()
keylist.sort()

mesh_out = open("mesh_key_value.txt", 'w')

for key in keylist:
    print key + " => " + mesh_hash[key]
    mesh_out.write(key + "\t" + mesh_hash[key] + "\n")
    
mesh_out.close()
        